#!/bin/bash
set -e
set -x
MYDIR="${0%/*}"
cd "$MYDIR/.."
source "recipes/common.sh"


# RECIPE START iputils
# depends: libcap
# depends: meson
# depends: ninja-native

rm -rf build/iputils
mkdir -p build/iputils
cd build/iputils

MESON_CROSS_FILE="`pwd`/${TARGET}-cross.txt"

cat > "${MESON_CROSS_FILE}" <<-EOF
[host_machine]
system = 'linux'
cpu = '${TARGET%%-*}'
cpu_family = '${TARGET%%-*}'
endian = 'little'

[binaries]
c = '${TARGET}-gcc'
cpp = '${TARGET}-g++'
ar = '${TARGET}-ar'
strip = '${TARGET}-strip'
pkgconfig = '${xtools}${build_prefix}/bin/${TARGET}-pkg-config'
EOF


env \
	CFLAGS="$CFLAGS" \
	LDFLAGS="$LDFLAGS" \
meson setup \
	--prefix=$prefix \
	--libdir=${prefix}/${target_libdir} \
	--localstatedir=/var/lib \
	-Dbuildtype=debugoptimized \
	-Dsystemdunitdir=$prefix/lib/systemd/system \
	-DINSTALL_SYSTEMD_UNITS=true \
	-DUSE_CAP=true \
	-DUSE_GETTEXT=false \
	-DSKIP_TESTS=true \
	-DUSE_IDN=false \
	-DBUILD_HTML_MANS=false \
	-DBUILD_MANS=false \
	--cross-file="$MESON_CROSS_FILE" \
	../../iputils

ninja -j${JOBS}
env DESTDIR="$stage" ninja install
cd ../..
rm -rf build/iputils

# RECIPE END iputils
